import SwiftUI
import Combine

// DetailView 专用的播放管理器 - 独立控制，不与其他组件共享
class DetailPlaybackManager: ObservableObject {
    @Published var currentPlayingVideoId: String?
    @Published var isPlaying = false
    @Published var isVideoReady = false
    private var cancellables = Set<AnyCancellable>()
    
    static let shared = DetailPlaybackManager()
    
    private init() {}
    
    // 开始播放视频
    func startPlaying(videoId: String) {
        print("🎬 DetailView 开始播放: \(videoId)")
        currentPlayingVideoId = videoId
        isPlaying = true
    }
    
    // 停止播放视频
    func stopPlaying() {
        print("⏹️ DetailView 停止播放")
        currentPlayingVideoId = nil
        isPlaying = false
        isVideoReady = false
    }
    
    // 暂停播放
    func pausePlaying() {
        print("⏸️ DetailView 暂停播放")
        isPlaying = false
    }
    
    // 恢复播放
    func resumePlaying() {
        print("▶️ DetailView 恢复播放")
        isPlaying = true
    }
    
    // 检查视频是否应该播放
    func shouldPlay(videoId: String) -> Bool {
        return currentPlayingVideoId == videoId && isPlaying
    }
    
    // 设置视频准备状态
    func setVideoReady(_ ready: Bool) {
        isVideoReady = ready
        print("📺 DetailView 视频准备状态: \(ready)")
    }
}
